var menu=[
		[
			{"name":"首页","top":1,"url":"home","file":"home","controller":"home"}
		],
		[
			{"name":"学院概况","top":1,"url":"profile","file":"profile","controller":"profile"},
		 	{"name":"学院简介","top":0,"url":"profile","file":"profile","controller":"profile"}
		],
		[
			{"name":"招生就业","top":1,"url":"profession","file":"profession","controller":"profession"},
		 	{"name":"成人教育","top":0,"url":"education","file":"profession","controller":"profession"},
		 	{"name":"招生就业","top":0,"url":"profession","file":"profession","controller":"profession"}
		],
		[
			{"name":"学院新闻","top":1,"url":"news","file":"news","controller":"news"},
		 	{"name":"新闻资讯","top":0,"url":"news","file":"news","controller":"news"},
		 	{"name":"学员通知","top":0,"url":"inform","file":"news","controller":"news"}
		],
		[
			// {"name":"学生管理","top":1,"url":"student","file":"student","controller":"news"},
		 	// {"name":"学生动态","top":0,"url":"student","file":"student","controller":"news"},
		 	// {"name":"重要通知","top":0,"url":"notice","file":"student","controller":"news"},
		 	// {"name":"学习平台","top":0,"url":"platform","file":"student","controller":"student"},
			 {"name":"学生管理","top":1,"url":"student","file":"news","controller":"news"},
		 	{"name":"学生动态","top":0,"url":"student","file":"news","controller":"news"},
		 	{"name":"重要通知","top":0,"url":"notice","file":"news","controller":"news"},
		 	{"name":"学习平台","top":0,"url":"platform","file":"news","controller":"student"},
		],
		[
			{"name":"资源下载","top":1,"url":"briefing","file":"resources","controller":"briefing"},
		 	{"name":"招生简章","top":0,"url":"briefing","file":"resources","controller":"briefing"},
			{"name":"学习资料","top":0,"url":"material","file":"resources","controller":"briefing"},
		],
		[
			{"name":"联系我们","top":1,"url":"apply","file":"contact","controller":"contact"},
			{"name":"网上报名","top":0,"url":"apply","file":"contact","controller":"contact"},
			{"name":"投诉电话","top":0,"url":"complaint","file":"contact","controller":"contact"},
		],
	]
var app=angular.module("app",['ui.router','ui.bootstrap']);
var routers=[];
app.config(function($stateProvider,$urlRouterProvider){
    $urlRouterProvider.when("","/home")
	angular.forEach(menu,function(data){
		angular.forEach(data,function(data){
			if(routers.indexOf(data.url)<0){
				routers.push(data.url);
				$stateProvider.state(data.url,{
					url:"/"+data.url,
					templateUrl:"/views/"+data.file+"/index.html",
					controller:data.controller,
				})
			}
		})
	})
	$stateProvider.state("detail",{
		url:"/detail/:currentState/:id",
		templateUrl:"/views/detail/index.html",
		controller:"detail",
	})
})
app.run(function($rootScope,$state){
	$rootScope.menu=menu;
	$rootScope.$on("$stateChangeSuccess",function(evt, toState, fromState, fromParams){
		$rootScope.currentState=toState.name;
		console.log($rootScope.currentState)
		angular.forEach(menu,function(data){
			angular.forEach(data,function(item){
				if(item.url==toState.name){
					$rootScope.currState=item.name;
					$rootScope.menuData=data;
				}
				if(toState.name=='detail'&&item.url==$state.params.currentState){
					console.log(data);
					$rootScope.menuData=data;
					$rootScope.currState=item.name;
				}
			})
		})
		// console.log($rootScope.menuData);
	})
	// if($state.params.currentState)
	
})